﻿using System;
using System.Windows;
using MyFloridaHouse.ServiceConn.DistrBldrSvcRef;


namespace MyFloridaHouse.libSvOpenDistricts.DataService
{
    public delegate void ServiceDALGetLayersCompletedEventHandler(LayerSTO sto);
    
    public partial class ServiceDAL
    {
        public static event ServiceDALGetLayersCompletedEventHandler GetLayersCompleted;

        // usage(called once at setup):
        // GetLayers(new System.EventHandler<GetLayersCompletedEventArgs>(GetLayersCompleted));
        public void GetLayers()
        {
            try
            {
				var proxy = new DistrBldrClient(_relativeBindingName);
                proxy.StartupGetLayersCompleted += ServiceGetLayersCompleted;
                proxy.StartupGetLayersAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void ServiceGetLayersCompleted(object sender, StartupGetLayersCompletedEventArgs args)
        {
            if (!IsError("GetLayersCompleted", args.Error, args.Result, args.Result.errorMessage))
            {
                RaiseGetLayersCompleted(this, args.Result);
            }
        }


        public static void RaiseGetLayersCompleted(object sender, LayerSTO sto)
        {
            if (GetLayersCompleted != null)
            {
                GetLayersCompleted(sto);
            }
            else
            {
                // todo: Log this error
                throw (new NotImplementedException("No Subscribers to ServiceDALGetLayersCompleted Event"));
            }
        }
    }
}
